<template>
    <div>
        <Title :title="title"></Title>
        <!-- 1.提供图标容器 -->
        <div ref="bottom3" style="height: 210px;margin-top: 30px;"></div>
    </div>
</template>
<script>
import { Line } from '@antv/g2plot';
import { get } from '@/utils/request';
import moment from 'moment';
import { Color } from '@antv/g2/lib/dependents';
export default {
    data() {
        return {
            title: '实时风速',
            params: {
                page: 1,
                pageSize: 100
            },
            tempData: []
        }
    },
    methods: {
        loadLine() {
            const linePlot = new Line(this.$refs.bottom3, {
                data: this.tempData,
                xField: 'insert_time',
                yField: 'wind_speed',
                stepType: 'vh',
               
                xAxis: {
                    label: {
                        style: {
                            fill: "white",
                            fontSize: 12,
                        },
                    },
                },
                yAxis: [
                    {
                        label: {
                            style: {
                                fill: "white",
                                fontSize: 13,
                            },
                        },
                    },
                ]
                
            });
        
            linePlot.render();
        },
        async getTempData() {
            let res = await get('/dashboard/pageQueryTodayData', this.params);
            console.log(res, "获取响应");
            let temp = [];
            // 将后端获取的数据设置给tempData
            res.data.list.forEach((item, index, arr) => {
                //由于刻度混乱
                arr[0].wind_speed = 2;
                // item表示数组每一项
                item.insert_time = moment(item.insert_time).format("HH:mm");
                //由于数据查询太密集 需要将数据处理 每隔10条获取数据
                if (index % 10 == 0) {
                    temp.push(arr[index])
                }
            });
            this.tempData = temp;
        }

    },
    async mounted() {
        await this.getTempData();
        this.loadLine();
    }
}
</script>
<style scoped></style>